package com.example.springbootrabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;

/**
 * tang
 * 应用启动后，会连接到rabbitmq创建对应的队列等
 */

@Service
public class RabbitMqFanoutInitService {

    // ======================以下是验证fanout Exchange的队列=====================
    @Bean
    public Queue AMessage() {
        return new Queue("fanout.A");
    }

    @Bean
    public Queue BMessage() {
        return new Queue("fanout.B");
    }

    @Bean
    public Queue CMessage() {
        return new Queue("fanout.C");
    }
    @Bean
    public Queue DMessage() {
        return new Queue("fanout.D");
    }

    @Bean
    FanoutExchange fanoutExchange() {
        return new FanoutExchange("fanoutExchange");
    }

    //绑定
    @Bean
    Binding bindingExchangeA(Queue AMessage,FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(AMessage).to(fanoutExchange);
    }

    @Bean
    Binding bindingExchangeB(Queue BMessage, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(BMessage).to(fanoutExchange);
    }

    @Bean
    Binding bindingExchangeC(Queue CMessage, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(CMessage).to(fanoutExchange);
    }

    @Bean
    Binding bindingExchangeD(Queue DMessage, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(DMessage).to(fanoutExchange);
    }

    // ======================以上是验证fanout Exchange的队列=====================




}
